#include <string.h>
#include <omnetpp.h>
#include "packettirt_m.h"

class NodeExpo : public cSimpleModule
{
  protected:
    // The following redefined virtual function holds the algorithm.
    virtual void initialize();
    virtual void handleMessage(cMessage *msg);
    virtual void finish();

  private:
    Packettirt *event;
    cLongHistogram delayStats;
    cOutVector delayVector;

};

// The module class needs to be registered with OMNeT++
Define_Module(NodeExpo);

void NodeExpo::initialize()
{
    delayStats.setName("delayStats");
    delayStats.setRangeAutoUpper(0, 10, 1.5);
    delayVector.setName("delayVector");

   simtime_t delay = par("delay");

   delayStats.collect(delay);
   delayVector.record(delay);

   event = new Packettirt("event");
   scheduleAt(simTime()+delay, event);
}

void NodeExpo::handleMessage(cMessage *msg)
{
    send(msg, "gate$o");
    simtime_t delay = par("delay");

    delayStats.collect(delay);
    delayVector.record(delay);

    event = new Packettirt("event");
    scheduleAt(simTime()+delay, event);
}

void NodeExpo::finish()
{
    delayStats.recordAs("delayStats");
}

